import javax.swing.*;

import java.awt.event.*;
import java.awt.*;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;


public class Run4HomeMain implements ActionListener {

	/**
	 * @param args
	 */
	
	public Run4HomeMain()
	{
	}
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		JFrame mainFrame = new JFrame("Run 4 Home");
		mainFrame.setSize(400, 300);
		mainFrame.setVisible(true);
		JFileChooser fileChooser = new JFileChooser();
		File folder = null;
		File[] listOfFiles = null;
		String[] readFiles = null;
		fileChooser.setDialogTitle("Select Directory for Output files");
		fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
		if(fileChooser.showOpenDialog(fileChooser) == JFileChooser.APPROVE_OPTION) {
			folder = fileChooser.getSelectedFile();
		}
		
		while(true) {
			listOfFiles = folder.listFiles();
			for(int i = 0; i < listOfFiles.length; i++) {
				if((Arrays.asList(readFiles).contains(listOfFiles[i])) == false) {
					System.out.println("test");
				}
				System.exit(0);
				FileInputStream fstream = null;
				try {
					fstream = new FileInputStream(listOfFiles[i]);
				} catch (FileNotFoundException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				readFiles[readFiles.length] = listOfFiles[i].getName();
				DataInputStream in = new DataInputStream(fstream);
				BufferedReader br = new BufferedReader(new InputStreamReader(in));
				String line;
				try {
					while((line = br.readLine()) != null) {
						System.out.println(line);
					}
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			
		}
	}
	
	public void actionPerformed(ActionEvent e)
	{
		
	}

}
